package com.imooc.authorization.context;

import com.imooc.authorization.entity.User;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/8/18.
 */
//TODO 待修改
public class LoginUserCache {


    private static Map<Long,LoginUser> cache=new HashMap<>();




    private static class LoginUser{

       private  long expire;
        private  User user;

        public long getExpire() {
            return expire;
        }

        public void setExpire(long expire) {
            this.expire = expire;
        }

        public User getUser() {
            return user;
        }

        public void setUser(User user) {
            this.user = user;
        }
    }


    /**
     *
     * @param user
     * @param expire 单位秒，如果是30分钟过期，即：60*30=1800
     */
    public static void put(User user,long expire){

        long exprireTime = Calendar.getInstance().getTime().getTime() +expire*1000;

                LoginUser loginUser=new LoginUser();
        loginUser.setUser(user);
        loginUser.setExpire(exprireTime);

        cache.put(user.getId(),loginUser);
    }

    public static void remove(User user) {

        cache.remove(user.getId());

    }

  /*  public static User get(){



    }*/


}
